using Microsoft.VisualBasic.CompilerServices;
using SJVars;
using SJXmlP.XMLClasses;
using Spacejock;
using System;
using System.Collections;
using System.Runtime.CompilerServices;
using System.Threading;
using yW5Lib;

namespace yWriter6
{
	public class clsPrintSceneList
	{
		public delegate void PrintProgressEventHandler(string ProgressString);

		[CompilerGenerated]
		private PrintProgressEventHandler PrintProgressEvent;

		public event PrintProgressEventHandler PrintProgress
		{
			[CompilerGenerated]
			add
			{
				PrintProgressEventHandler printProgressEventHandler = PrintProgressEvent;
				PrintProgressEventHandler printProgressEventHandler2;
				do
				{
					printProgressEventHandler2 = printProgressEventHandler;
					PrintProgressEventHandler value2 = (PrintProgressEventHandler)Delegate.Combine(printProgressEventHandler2, value);
					printProgressEventHandler = Interlocked.CompareExchange(ref PrintProgressEvent, value2, printProgressEventHandler2);
				}
				while ((object)printProgressEventHandler != printProgressEventHandler2);
			}
			[CompilerGenerated]
			remove
			{
				PrintProgressEventHandler printProgressEventHandler = PrintProgressEvent;
				PrintProgressEventHandler printProgressEventHandler2;
				do
				{
					printProgressEventHandler2 = printProgressEventHandler;
					PrintProgressEventHandler value2 = (PrintProgressEventHandler)Delegate.Remove(printProgressEventHandler2, value);
					printProgressEventHandler = Interlocked.CompareExchange(ref PrintProgressEvent, value2, printProgressEventHandler2);
				}
				while ((object)printProgressEventHandler != printProgressEventHandler2);
			}
		}

		public void PrintSceneList(clsProject cProject)
		{
			//Discarded unreachable code: IL_02ed, IL_0304, IL_030f, IL_031f, IL_03f9, IL_03fb, IL_040f, IL_0431
			int num = default(int);
			int num3 = default(int);
			try
			{
				ProjectData.ClearProjectError();
				num = 2;
				int num2 = 2;
				num2 = 3;
				if (cProject.ChapterCount != 0)
				{
					num2 = 5;
					frmPickChapters frmPickChapters = new frmPickChapters(ref cProject);
					num2 = 6;
					frmPickChapters.ShowDialog();
					num2 = 7;
					if (!frmPickChapters.Cancelled)
					{
						num2 = 8;
						clsCollection<int> pickedIDs = frmPickChapters.PickedIDs;
						num2 = 9;
						clsShared.cSubs.BusyMouse();
						num2 = 10;
						clsReport clsReport = new clsReport(ref clsShared.cLog, ref clsShared.cSettings, "Scene List from " + cProject.Title);
						num2 = 11;
						clsReport.AddTitle();
						num2 = 12;
						clsReport.AddBR(2);
						num2 = 13;
						clsReport.OpenTable("cellpadding=5");
						num2 = 14;
						IEnumerator enumerator = pickedIDs.GetEnumerator();
						bool flag2 = default(bool);
						while (enumerator.MoveNext())
						{
							int iD = Conversions.ToInteger(enumerator.Current);
							num2 = 15;
							clsChapter clsChapter = cProject.Chapters.ChapterByID(iD);
							num2 = 16;
							if (frmPickChapters.WithUnused | !clsChapter.Unused)
							{
								num2 = 17;
								bool flag = false;
								num2 = 18;
								int sceneCount = clsChapter.SceneCount;
								for (int i = 1; i <= sceneCount; i++)
								{
									num2 = 19;
									clsScene clsScene = cProject.get_SceneByID(clsChapter.get_SceneIDByIndex(i));
									num2 = 20;
									if (frmPickChapters.WithUnused | !clsScene.Unused)
									{
										num2 = 21;
										clsReport.OpenRow();
										num2 = 22;
										if (!flag)
										{
											num2 = 23;
											clsReport.AddCell(clsChapter.ShortTitle(), "width=10%");
											num2 = 24;
											flag = true;
										}
										else
										{
											num2 = 26;
											clsReport.AddCell("");
										}
										num2 = 27;
										clsReport.OpenCell();
										num2 = 28;
										clsReport.AddText("<B>" + Conversions.ToString(i) + ")</B> ");
										num2 = 29;
										clsReport.AddText(clsScene.Title + "<br />");
										num2 = 30;
										if (!cProject.V6File)
										{
											num2 = 31;
											clsReport.AddText("File: <a href='file:///" + yW5Lib.modSubs.RTFPathV5(cProject.ProjectPath()) + "\\" + clsScene.RTFFilename + "'>" + clsScene.RTFFilename + "</a>");
										}
										num2 = 32;
										clsReport.CloseCell();
										num2 = 33;
										clsReport.CloseRow();
										num2 = 34;
										flag2 = true;
									}
									num2 = 35;
								}
							}
							num2 = 36;
						}
						num2 = 37;
						if (enumerator is IDisposable)
						{
							(enumerator as IDisposable).Dispose();
						}
						num2 = 38;
						clsReport.CloseCell();
						num2 = 39;
						clsReport.CloseRow();
						num2 = 40;
						clsReport.CloseTable();
						num2 = 41;
						clsReport.AddFooter(App.Title);
						num2 = 42;
						if (flag2)
						{
							num2 = 43;
							clsReport.Show();
							num2 = 44;
							PrintProgressEvent?.Invoke("Printing Complete");
						}
						else
						{
							num2 = 46;
							clsShared.cLang.TransMsgBox("There are no scenes to print");
						}
						num2 = 47;
						clsShared.cSubs.NormalMouse();
					}
				}
			}
			catch (Exception obj) when ((obj is Exception && num != 0) & (num3 == 0))
			{
				ProjectData.SetProjectError((Exception)obj);
				/*Error near IL_042f: Could not find block for branch target IL_03fb*/;
			}
			if (num3 != 0)
			{
				ProjectData.ClearProjectError();
			}
		}
	}
}
